/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package main;

import bean.Category;
import bean.Label;
import bean.RSSChannel;
import facade.CategoryFacade;
import facade.LabelFacade;
import facade.RSSChannelFacade;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.*;

/**
 * @author penyihirkecil
 */
public class LabelingMidlet extends MIDlet implements CommandListener{
    private Display display;
    private Alert alert;
    private Form form;
    private Command exit;
    private Command start;
    private CategoryFacade categoryFacade;
    private RSSChannelFacade rssChannelFacade;
    private LabelFacade labelFacade;
    private Filter filter;
    
    public LabelingMidlet(){
        display = Display.getDisplay(this);
        exit = new Command("Exit", Command.SCREEN, 1);
        start = new Command("Start", Command.SCREEN, 1);
        form = new Form("Mixed RecordEnumeration");
        filter = new Filter(searchcriteria);
        form.addCommand(exit);
        form.addCommand(start);
        form.setCommandListener(this);
    }
    public void startApp() {
        display.setCurrent(form);
        
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        
    }

    public void commandAction(Command command, Displayable displayable) {
        if (command == exit){
            destroyApp(true);
            notifyDestroyed();
        }else if (command == start){
           if(getLabelFacade().getLabelRS().getNbLabel()==0){
               Label lbl = new Label();
               lbl.setRecIdCategory(1);
               lbl.setRecIdRSS(2);

               Label lbl2 = new Label();
               lbl2.setRecIdCategory(3);
               lbl2.setRecIdRSS(4);

               getLabelFacade().addLabel(lbl);
               getLabelFacade().addLabel(lbl2);
           }
        }
    
    }

    public CategoryFacade getCategoryFacade() {
        if(categoryFacade==null)
            categoryFacade = new CategoryFacade();
        return categoryFacade;
    }

    public RSSChannelFacade getRssChannelFacade() {
        if(rssChannelFacade==null)
            rssChannelFacade = new RSSChannelFacade();
        return rssChannelFacade;
    }

    public LabelFacade getLabelFacade() {
        if(labelFacade==null){
            labelFacade = new LabelFacade();
        }
        return labelFacade;
    }
    
    
}
